package common;

import java.util.HashMap;

public class MetricsRecord {
	private static final String SEPARATOR = "\1";
	private static final int COLUMN_COUNT = 12;
	public static final String[] FEATURE_LIST = {"orderByType", "searchStyle", "query",
		"preCategory", "itemId", "postCategory", "sellerId", "sellerType", "sellerDegree"}; 
	private long pvCount = 0;
	private long clickCount = 0;
	private long bargainCount = 0;
	private HashMap<String, String> featureMap;
	
	public MetricsRecord(String line) throws Exception 
	{
		String[] strs = line.trim().split(SEPARATOR);
		if (strs.length != COLUMN_COUNT){
			System.out.println("column count: " + strs.length);
			for (String s : strs)
				System.out.println(s);
			throw new Exception("error: metrics format is not correct");
		}
		
		featureMap = new HashMap<String, String>();
		
		for (int i = 0; i < FEATURE_LIST.length; ++i){
			featureMap.put(FEATURE_LIST[i].toLowerCase(), strs[i]);
		}		
		pvCount = Integer.parseInt(strs[10]);
		clickCount = Integer.parseInt(strs[9]);
		bargainCount = Integer.parseInt(strs[11]);
	}
	
	public String getValue(String featureName){
		return featureMap.get(featureName);
	}
	
	public long getPVCount(){
		return pvCount;
	}
	
	public long getClickCount(){
		return clickCount;
	}
	
	public long getBargainCount(){
		return bargainCount;
	}
}
